package test;

import java.util.Scanner;
import java.util.TreeMap;

public class Demo1 {
    static Object lock = new Object();
    static int n = 0;

    static volatile int isQuite = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
           while (isQuite == 0);
            System.out.println("线程执行结束");
        });
        t1.start();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数");
        isQuite = sc.nextInt();
        System.out.println("main执行结束");
    }

    public static void main2(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
//            synchronized(lock){
                while (true) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
//            }
        },"t1");
        Thread t2 = new Thread(() -> {
            synchronized(lock){
                for (int i = 0; i < 10000; i++) {

                }
            }
        },"t2");
        System.out.println("t1 is new? " + t1.getState());
//        System.out.println("t2 is new? " + t2.getState());
        t1.start();
        t2.start();
        Thread.sleep(100);
        System.out.println("t1 is running? " + t1.getState());
//        System.out.println("t2 is running? " + t2.getState());
//        t1.join();
//        t2.join();
//        System.out.println("t1 is terminated? " + t1.getState());
//        System.out.println("t2 is terminated? " + t2.getState());

    }

    private static void testMethod(){
        System.out.println("testMethod");
    }
    public static void main1(String[] args) {
        ((Demo1)null).testMethod();

    }


}
